﻿using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;

namespace 提取房间号
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_DragDrop(object sender, DragEventArgs e)
        {
            string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            string content = File.ReadAllText(path);


            textBox1.Text = FindRoomList(content);
            this.textBox1.Cursor = System.Windows.Forms.Cursors.IBeam; //还原鼠标形状
        }

        private void textBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Link;
                this.textBox1.Cursor = System.Windows.Forms.Cursors.Arrow;  //指定鼠标形状（更好看）
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
        private string FindRoomList(string s)
        {
            MatchCollection m = Regex.Matches(s, @"(?<=,)\d{4}(?=,)");
            Dictionary<string, bool> r = new Dictionary<string, bool> { };
            string rooms="";
            foreach (var item in m)
            {
                
                if (!r.ContainsKey(item.ToString())) 
                {
                    r.Add(item.ToString(), true);
                    rooms += item.ToString() + ",";
                }
                    
            }
            //
            toolStripStatusLabel1.Text = "房间数量:" + r.Count.ToString();
            return rooms;
        }
    }

}
